﻿@page "/Fin/OtherOutlay/Edit"
@using nERP.ViewModel.Fin.OtherOutlayVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <BootstrapInput @bind-Value="@Model.Entity.OtherOutlayCode" Readonly="true" />
            <Select @bind-Value="@Model.Entity.SupplierId" Items="AllSuppliers" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
            <Select @bind-Value="@Model.Entity.MakeUserId" Items="AllMakeUsers" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
            <DateTimePicker @bind-Value="@Model.Entity.InvoicesDate" />
            <Select @bind-Value="@Model.Entity.SettlementAccountId" Items="AllSettlementAccounts" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
            <Select @bind-Value="@Model.Entity.OutlayTypeId" Items="AllOutlayTypes" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
            <BootstrapInput @bind-Value="@Model.Entity.TotalPrice" FormatString="0.##" />
            <BootstrapInput @bind-Value="@Model.Entity.Remark" />
            <WTUploadImage @bind-Value="@Model.Entity.InvoicesImage" />
        </Row>

        <div class="modal-footer table-modal-footer">
            <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" />
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private OtherOutlayVM Model = new OtherOutlayVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Fin/OtherOutlay/Edit", (s) => "Sys.OprationSuccess", method: HttpMethodEnum.PUT);
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllSuppliers = new List<SelectedItem>();
    private List<SelectedItem> AllMakeUsers = new List<SelectedItem>();
    private List<SelectedItem> AllSettlementAccounts = new List<SelectedItem>();
    private List<SelectedItem> AllOutlayTypes = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllSuppliers = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherOutlay/GetSuppliers");
        AllSuppliers.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllMakeUsers = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherOutlay/GetFrameworkUsers");
        AllMakeUsers.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSettlementAccounts = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherOutlay/GetSettlementAccounts");
        AllSettlementAccounts.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllOutlayTypes = await WtmBlazor.Api.CallItemsApi("/api/Fin/OtherOutlay/GetDicFields其他支出类别");
        AllOutlayTypes.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<OtherOutlayVM>($"/api/Fin/OtherOutlay/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
